package com.batata.continuing.web.tree;

import com.batata.continuing.config.moreNote.token.NotNeedToken;
import com.batata.continuing.pojo.base.ResultData;
import com.batata.continuing.pojo.tree.TreeInfo;
import com.batata.continuing.pojo.tree.TreeInfoAll;
import com.batata.continuing.service.tree.TreeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@Api(tags = "枚举相关接口")
@RestController
@RequestMapping("/tree")
public class TreeController {


    @Autowired
    private TreeService treeService;


    @ApiOperation("创建新的枚举")
    @PostMapping("/createUser")
    public ResultData<Object> createTree(TreeInfo treeInfo) {
        return treeService.createTree(treeInfo);
    }


    @ApiOperation("查询所有的节点")
    @PostMapping("/getAllTree")
    public TreeInfoAll getAllTree() {
        return treeService.getAllTree();
    }

    @NotNeedToken
    @ApiOperation("查询所有的节点")
    @PostMapping("/getAllTreeNew")
    public List<TreeInfoAll> getAllTreeNew() {
        List<TreeInfoAll> allTreeNew = null;
        try {
            allTreeNew = treeService.getAllTreeNew();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }

        return allTreeNew;
    }

    @ApiOperation("根据treeid查询节点详细信息")
    @PostMapping("/getNodeByTreeId")
    @ApiImplicitParam(name = "treeId", value = "节点id", required = true, dataType = "String")
    public TreeInfo getNodeByTreeId(String treeId) {
        return treeService.getNodeByTreeId(treeId);
    }


    @ApiOperation("根据父节点id查询所有的子节点(不包括孙节点)")
    @PostMapping("/getChildNodeByPareatId")
    @ApiImplicitParam(name = "pareatId", value = "父节点的id", required = true, dataType = "String")
    public List<TreeInfo> getChildNodeByPareatId(String pareatId) {
        return treeService.getChildNodeByPareatId(pareatId);
    }


}
